package com.jsgt.greekfire.ui.coin

import android.os.Bundle
import androidx.recyclerview.widget.LinearLayoutManager
import com.fhx.core.base.BaseFragment
import com.fhx.core.utils.LogUtils
import com.fhx.core.utils.ToastUtils
import com.jsgt.greekfire.R
import com.jsgt.greekfire.ui.coin.adapter.CoinsOrderAdapter
import com.jsgt.greekfire.ui.coin.adapter.HistoricalOrderAdapter
import com.jsgt.greekfire.ui.coin.ordermanagement.HistoricalOrdersBean
import com.jsgt.greekfire.ui.coin.ordermanagement.HistoricalOrdersFragment
import kotlinx.android.synthetic.main.fragment_coins_order.*
import kotlinx.android.synthetic.main.fragment_historical_orders.*

private const val ARG_PARAM1 = "param1"

class CoinsOrderFragment : BaseFragment() {
    private var param1: String? = null
    var carList = mutableListOf<CoinsOrderBean>()
    private val historicalOrderAdapter by lazy {
        CoinsOrderAdapter(context!!, R.layout.item_coins_order_list)
    }

    override fun getLayoutId(): Int = R.layout.fragment_coins_order

    companion object {
        @JvmStatic
        fun newInstance(param1: String) =
            CoinsOrderFragment().apply {
                arguments = Bundle().apply {
                    putString(ARG_PARAM1, param1)
                }
            }
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        arguments?.let {
            param1 = it.getString(ARG_PARAM1)
        }
    }

    override fun main() {
        var bean1 = CoinsOrderBean("1", "GFT", "2020-07-12 08:12:08", "已取消", "45.87", "7564.87", "6466.654")
        var bean2 = CoinsOrderBean("2", "ETH", "2020-08-06 12:07:37", "已完成", "6461.1", "654.64", "65460.984")
        var bean3 = CoinsOrderBean("1", "BTC", "2020-10-23 24:45:03", "未完成", "84561", "984", "9984.94")
        var bean4 = CoinsOrderBean("1", "GFT", "2020-07-12 08:12:08", "已取消", "45.87", "7564.87", "6466.654")
        var bean5 = CoinsOrderBean("2", "ETH", "2020-08-06 12:07:37", "已完成", "6461.1", "654.64", "65460.984")
        LogUtils.error("param1 ==" + param1);
        rvCoinsOrder.layoutManager = LinearLayoutManager(context)
        rvCoinsOrder.adapter = historicalOrderAdapter
        historicalOrderAdapter.setOnItemClickListener { adapter, view, position ->
            ToastUtils.show(activity!!, historicalOrderAdapter.data.get(position).currency)
        }
        if (param1.equals("未完成")) {
            carList.add(bean3)
            historicalOrderAdapter?.setNewData(carList)
        } else if (param1.equals("已完成")) {
            carList.add(bean2)
            carList.add(bean5)
            historicalOrderAdapter?.setNewData(carList)
        } else if (param1.equals("已取消")) {
            carList.add(bean1)
            carList.add(bean4)
            historicalOrderAdapter?.setNewData(carList)
        }


    }
}